package com.hualan.sfzy.controller;

import com.hualan.sfzy.model.dto.ConsultReservationDto;
import com.hualan.sfzy.model.entity.ConsultReservation;
import com.hualan.sfzy.model.vo.ConsultReservationQuery;
import com.hualan.sfzy.service.ConsultReservationService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.hualan.sfzy.constant.CommonConstant.*;

/**
 * 咨询预约管理控制器
 */
@RestController
@RequestMapping("/consultReservation")
public class ConsultReservationController {

    @Autowired
    private ConsultReservationService consultReservationService;

    /**
     * 添加咨询预约
     */
    @PostMapping("/add")
    public Result add(@RequestBody ConsultReservation consultReservation) {
        int result = consultReservationService.add(consultReservation);
        return result > 0 ? Result.success() : Result.error();
    }

    /**
     * 编辑咨询预约
     */
    @PutMapping("/edit")
    public Result edit(@RequestBody ConsultReservation consultReservation) {
        int result = consultReservationService.edit(consultReservation);
        return result > 0 ? Result.success() : Result.error();
    }

    /**
     * 删除咨询预约
     */
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Integer id) {
        int result = consultReservationService.remove(id);
        return result > 0 ? Result.success() : Result.error();
    }

    /**
     * 批量删除咨询预约
     */
    @DeleteMapping("/removeBatch")
    public Result removeBatch(@RequestBody Integer[] ids) {
        int result = consultReservationService.removeBatch(ids);
        return result > 0 ? Result.success() : Result.error();
    }

    /**
     * 查询所有咨询预约
     */
    @GetMapping("/find")
    public Result find() {
        List<ConsultReservationDto> consultReservations = consultReservationService.findAll();
        return Result.success(consultReservations);
    }

//    /**
//     * 分页查询咨询预约
//     */
//    @GetMapping("/findPage")
//    public Result findPage(@RequestParam(value = PAGE_NUM, defaultValue = PAGE_NUM_DEFAULT) Integer pageNum,
//                          @RequestParam(value = PAGE_SIZE, defaultValue = PAGE_SIZE_DEFAULT) Integer pageSize,
//                          ConsultReservation consultReservation) {
//        Map<String, Object> result = consultReservationService.findPage(pageNum, pageSize, consultReservation);
//        return Result.success(result);
//    }

    /**
     * 根据ID查询咨询预约
     */
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable Integer id) {
        ConsultReservation consultReservation = consultReservationService.findById(id);
        return Result.success(consultReservation);
    }

    /**
     * 分页条件查询咨询预约
     */
    @GetMapping("/findReservationPage")
    public Result findReservationPage(@RequestParam(value = PAGE_NUM, defaultValue = PAGE_NUM_DEFAULT) Integer pageNum,
                                     @RequestParam(value = PAGE_SIZE, defaultValue = PAGE_SIZE_DEFAULT) Integer pageSize,
                                     ConsultReservationQuery query) {
        Map<String, Object> result = consultReservationService.findReservationPage(pageNum, pageSize, query);
        return Result.success(result);
    }
} 